{% extends "base.html" %}

{% block title %}首页 - {{ super() }}{% endblock %}

{% block content %}
<!-- 轮播图 -->
<div id="heroCarousel" class="carousel slide mb-4" data-bs-ride="carousel">
    <div class="carousel-indicators">
        {% for image in hero_images %}
            <button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="{{ loop.index0 }}"
                    {% if loop.first %}class="active"{% endif %}></button>
        {% endfor %}
    </div>
    <div class="carousel-inner">
        {% for image in hero_images %}
            <div class="carousel-item {% if loop.first %}active{% endif %}">
                <img src="{{ image.image_path }}" class="d-block w-100" alt="{{ image.image_title }}"
                     style="height: 400px; object-fit: cover;">
                <div class="carousel-caption d-none d-md-block">
                    <h5>{{ image.image_title }}</h5>
                    <p>{{ image.image_subtitle }}</p>
                </div>
            </div>
        {% endfor %}
    </div>
    <button class="carousel-control-prev" type="button" data-bs-target="#heroCarousel" data-bs-slide="prev">
        <span class="carousel-control-prev-icon"></span>
        <span class="visually-hidden">Previous</span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#heroCarousel" data-bs-slide="next">
        <span class="carousel-control-next-icon"></span>
        <span class="visually-hidden">Next</span>
    </button>
</div>

<!-- 动态列表 -->
<div class="row">
    <div class="col-md-8">
        <h2 class="mb-4">最新动态</h2>
        {% if current_user.is_authenticated %}
            <div class="card mb-4">
                <div class="card-body">
                    <form action="{{ url_for('main_bp_zc.new_post') }}" method="GET">
                        <div class="d-grid">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-plus"></i> 发布新动态
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        {% endif %}
        
        {% for post in posts %}
            <div class="card mb-4">
                <div class="card-body">
                    <div class="d-flex align-items-center mb-3">
                        <img src="{{ post.user.avatar_url }}" alt="{{ post.user.nickname }}" 
                             class="rounded-circle me-2" width="40" height="40">
                        <div>
                            <h5 class="card-title mb-0">{{ post.user.nickname }}</h5>
                            <small class="text-muted">{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</small>
                        </div>
                    </div>
                    <p class="card-text">{{ post.content }}</p>
                    {% if post.image_url %}
                        <img src="{{ post.image_url }}" class="img-fluid rounded mb-3" alt="动态图片">
                    {% endif %}
                    {% if current_user.is_authenticated and current_user.id == post.user_id %}
                        <form action="{{ url_for('main_bp_zc.delete_post', id=post.id) }}" method="POST" 
                              class="d-inline" onsubmit="return confirm('确定要删除这条动态吗？');">
                            <button type="submit" class="btn btn-danger btn-sm">
                                <i class="fas fa-trash"></i> 删除
                            </button>
                        </form>
                    {% endif %}
                </div>
            </div>
        {% else %}
            <div class="alert alert-info">
                暂无动态，快来发布第一条吧！
            </div>
        {% endfor %}
    </div>
    
    <!-- 侧边栏 -->
    <div class="col-md-4">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">关于我</h5>
            </div>
            <div class="card-body">
                <p>我是南京审计大学金审学院信息管理与信息系统专业的学生张驰，学号：js22150332。</p>
                <p>我热爱探索信息技术的前沿，对数据分析和系统设计抱有浓厚兴趣，并致力于将所学应用于实际问题的解决。</p>
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">联系方式</h5>
            </div>
            <div class="card-body">
                <ul class="list-unstyled mb-0">
                    <li><i class="fas fa-envelope me-2"></i> 邮箱：15116672656@163.com</li>
                    <li><i class="fas fa-map-marker-alt me-2"></i> 地址：江苏省南京市浦口区</li>
                </ul>
            </div>
        </div>
    </div>
</div>
{% endblock %} 